import _ from "lodash";

// 工序表
const works = [
  {
    label: "船体下料",
    value: "0",
  },
  {
    label: "船体割旧",
    value: "1",
  },
  {
    label: "船体焊接",
    value: "2",
  },
  {
    label: "机电焊接",
    value: "3",
  },
  {
    label: "拖轮油耗",
    value: "4",
  },
  {
    label: "其它油耗",
    value: "5",
    children: [
      { label: "单船", value: "5-0" },
      { label: "高空车", value: "5-1" },
    ],
  },
  {
    label: "涂装喷漆",
    value: "6",
    children: [
      { label: "舱室及船壳喷漆", value: "6-0" },
      { label: "喷漆房分段喷漆", value: "6-1" },
    ],
  },
  {
    label: "打砂除锈",
    value: "7",
    children: [
      { label: "舱室打砂", value: "7-0" },
      { label: "打砂房分段打砂", value: "7-1" },
    ],
  },
  {
    label: "超水除锈",
    value: "8",
  },
  {
    label: "移动电箱",
    value: "9",
  },
];

const flatWorks = _.reduce(
  works,
  (arr, work) => {
    if (work.children) {
      arr = arr.concat(work.children);
    } else {
      arr.push({ label: work.label, value: work.value });
    }
    return arr;
  },
  []
);

// 根据值获取工序
const getValueByLabel = (v) => {
  const one = _.find(flatWorks, { label: v });
  return one?.value;
};

export { works, getValueByLabel, flatWorks };
